import request from '@/utils/request'

// api 后端接口
export function deviceAdd(data) {
  return request({
    url: '/vue-admin-template/user/deviceAdd',
    method: 'post',
    data: data
  })
}

export function initDevices() {
  return request({
    url: '/vue-admin-template/user/initdevices',
    method: 'post',
    data: {}
  })
}

export function deviceDel(data) {
  return request({
    url: '/vue-admin-template/user/deviceDel',
    method: 'post',
    data: data
  })
}

export function deviceEdit(data) {
  return request({
    url: '/vue-admin-template/user/deviceEdit',
    method: 'post',
    data: data
  })
}
// api end

// json反序列化
export function unserializer(json) {
  var devices = []
  for (var i = 0; i < json.length; i++) {
    const element = json[i]
    console.log('反序列化')
    console.log(element.model)
    if (element.model === 'vue_app.devicemgrtable') {
      devices.push({
        deviceID: element.fields.device_id,
        address: element.fields.description,
        name: '',
        disabled: true,
        btnText: '编辑'
      })
    }
  }
  return devices
}
